package com.hzjy.api.controller;

import com.hzjy.api.beans.HzjyProduct;
import com.hzjy.api.service.BqTokenService;
import com.hzjy.api.service.impl.ApiProductServiceImpl;
import com.hzjy.api.vo.BqLoginUser;
import com.hzjy.api.vo.BqUser;
import com.hzjy.common.core.controller.ApiBaseController;
import com.hzjy.common.core.controller.BaseApiController;
import com.hzjy.common.core.domain.AjaxResult;
import com.hzjy.common.utils.PageData;
import com.hzjy.common.utils.ServletUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 产品页
 *
 * @author SS
 */
@Api("产品页")
@RestController
@RequestMapping("/api/product")
public class ApiProductController extends BaseApiController {
    private static final Logger log = LoggerFactory.getLogger(ApiBaseController.class);
    @Autowired
    private ApiProductServiceImpl apiProductService;

    @Autowired
    private BqTokenService bqTokenService;

    /**
     * 产品详情页(所有产品的详情页)
     */
    @ApiOperation("产品详情页")
    @PostMapping("/info")
    public AjaxResult addProduct(@RequestBody PageData pd) {
        Object productId = pd.get("productId");
        log.info("【打开产品详情页】,产品ID:" + productId);
        HzjyProduct hzjyProduct = new HzjyProduct();
        hzjyProduct.setProductId(Long.valueOf(productId.toString()));
        BqLoginUser loginUser = bqTokenService.getBqLoginUser(ServletUtils.getRequest());
        if (loginUser != null) {
            BqUser bqUser = loginUser.getBqUser();
            Long userId = bqUser.getUserId();
            hzjyProduct.setUserId(Integer.parseInt(userId.toString()));
        }
        return AjaxResult.success(200, "查询成功", apiProductService.queryProductInfo(hzjyProduct));
    }
}
